// getPinyin.js
const app = getApp();

function getPinyinFirstLetter(name) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'http://localhost:3000/pinyin/getPinyinFirstLetter',
      method: 'POST',
      header: {
        'Content-Type': 'application/json',
        'Authorization': app.globalData.userToken // 使用全局的 userToken
      },
      data: { name },
      success: function (res) {
        if (res.data.code === 200) {
          resolve(res.data.data.firstLetter);
        } else {
          reject(res.data.msg);
        }
      },
      fail: function (error) {
        reject(error);
      }
    });
  });
}

module.exports = {
  getPinyinFirstLetter
};
